﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace ACBDP
{
    [ContentProperty(Name = "ItemsSource")]
    public partial class AutoCompleteBox : Control
    {
        private ListBox lb;

        /// <summary>
        /// Gets or sets a local cached copy of the items data.
        /// </summary>
        private List<object> _items;
        private ObservableCollection<object> _view;

        public AutoCompleteBox()
            : base()
        {
            DefaultStyleKey = typeof(AutoCompleteBox);
            Loaded += (sender, e) => ApplyTemplate();
            
        }
        protected override void OnApplyTemplate()
        {
            this.lb = this.GetTemplateChild("Selector") as ListBox;
            base.OnApplyTemplate();

        }
        #region ItemsSource

        public IEnumerable ItemsSource
        {
            get { return GetValue(ItemsSourceProperty) as IEnumerable; }
            set { SetValue(ItemsSourceProperty, value); }
        }

        public static readonly DependencyProperty ItemsSourceProperty =
            DependencyProperty.Register(
                "ItemsSource",
                typeof(IEnumerable),
                typeof(AutoCompleteBox),
                new PropertyMetadata(null, OnItemsSourcePropertyChanged));

        private static void OnItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //this never gets called 
            AutoCompleteBox autoComplete = d as AutoCompleteBox;
            autoComplete.OnItemsSourceChanged((IEnumerable)e.OldValue, (IEnumerable)e.NewValue);
        }

    
        private void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
         

        }
        #endregion public IEnumerable ItemsSource

        #region public string searchText

        public String SearchText
        {
            get { return GetValue(SearchTextProperty) as String; }
            set
            {
                SetValue(SearchTextProperty, value);
            }
        }


        public static readonly DependencyProperty SearchTextProperty =
            DependencyProperty.Register(
                "SearchText",
                typeof(String),
                typeof(AutoCompleteBox),
                new PropertyMetadata(null, OnSearchTextPropertyChanged));

        private static void OnSearchTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            //this gets called, as expected
        }


        #endregion

       
    }
}
